import { GameComponent } from "@sapi-game/main";
import { HideAndSeekMainState } from "../mainState";
import { HideAndSeekRole } from "../player";

export class SeekerDrawer extends GameComponent<HideAndSeekMainState> {
    override onAttach(): void {}

    /**抽追捕者 */
    drawSeeker(num: number = 1) {
        const seekers = [];
        for (let i = 0; i < num; i++) {
            const randomPlayer = this.context.players.random();
            if (randomPlayer) {
                seekers.push(randomPlayer);
            }
        }
        if (seekers.length == 0) {
            this.context.players.sendMessage("抽取抓捕者失败，游戏结束！");
            this.state.end();
            return;
        }
        seekers.forEach((p) => (p.role = HideAndSeekRole.Seeker));
        //消息提示
        this.context.players.sendMessage(
            `§c ${seekers.map((p) => p.name).join(",")} 成为了追捕者`
        );
    }
}
